package com.zhiyou.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.javassist.compiler.ast.Visitor;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhiyou.model.FyVisitor;
import com.zhiyou.service.VisitorService;
import com.zhiyou.utils.JsonResult;

@RestController		//代表下面所有的mapping都是返回json的
@RequestMapping("visitor/")
public class VisitorController {
	
	@Autowired
	VisitorService service;
	
	//查询全部
	@GetMapping(value="list")
	public JsonResult show(HttpServletRequest req, HttpServletResponse resp){
		return new JsonResult(200, service.selectall(), "查询成功！");
		
	}
	
	//添加
	@PostMapping("add/")
	public JsonResult add(Visitor visitor,HttpServletRequest req, HttpServletResponse resp){
		
		return new JsonResult(200, "添加成功！");
	}
	//当天来访记录
	@GetMapping("selectDate/")
	public JsonResult selectDate(HttpServletRequest req, HttpServletResponse resp){
		
		return new JsonResult(200, service.selectDate(), "查询成功！");
	}
	
	/**
	 *  visitor_apply_status = 1时代表已通过，等于2时代表申请未审批，等于3时代表申请已拒绝
	 * 
	 */
	//申请记录(已审核)
	@GetMapping("recorded/")
	public JsonResult recorded(HttpServletRequest req, HttpServletResponse resp){
		
		return new JsonResult(200, service.recorded(), "查询成功！");
		
	}
	//申请记录(未审核)
	@GetMapping("record/")
	public JsonResult record(HttpServletRequest req, HttpServletResponse resp){
		
		return new JsonResult(200, service.record(), "查询成功！！");
		
	}
	//来访记录(本月)
	@GetMapping("visitorRecord/")
	public JsonResult visitorRecord(HttpServletRequest req, HttpServletResponse resp){
		
		return new JsonResult(200, service.selectMonth(),"查询成功！");
	}
	//来访人数
	@GetMapping("selectSum/")
	public JsonResult selectSum(HttpServletRequest req, HttpServletResponse resp){
			
	return new JsonResult(200, service.selectNum(),"查询成功！");
		}
	//删除访客记录
	@DeleteMapping("delete/{visitor_id}")
	public JsonResult delete(@PathVariable("visitor_id")Integer visitor_id,HttpServletRequest req, HttpServletResponse resp){
		service.delete(visitor_id);
		return new JsonResult(200,"删除成功！！");
			}
	//修改
	@PutMapping("update/")
	public JsonResult update(FyVisitor visitor,HttpServletRequest req, HttpServletResponse resp){
		service.update(visitor);
		return new JsonResult(200,"修改成功！");
			}
	//根据id查询
	@GetMapping("selectById/{visitor_id}")
	public JsonResult selectById(@PathVariable("visitor_id")Integer visitor_id,HttpServletRequest req, HttpServletResponse resp){
		return new JsonResult(200, service.selectByid(visitor_id), "查询成功！！");
		
	}
	
	
		
}
